#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<fcntl.h>
#include<string.h>
int fun1() //重定向问题
{
  const char* msg1 = "hello 标准输出!\n";
  write(1,msg1,strlen(msg1));

  
  printf("printf\n");
  fprintf(stdout, "fprintf\n");
  fputs("fputs\n", stdout);
  fork();

  return 0;
}
int fun2()//缓冲区问题
{
  close(1);//关闭显示器文件，指向文件，刷新策略变成全缓冲
  int fd = open("./log.txt", O_CREAT|O_WRONLY,0666);
  printf("fd: %d\n", fd);

  printf("hello world!\n");
  fprintf(stdout,"hello world!\n");
  fprintf(stdout,"hello world!\n");
  fprintf(stdout,"hello world!\n");
  fprintf(stdout,"hello world!\n");
 
  close(fd);
  return 0;
}
int main()
{
   //fun1();
  fun2();
   return 0;
}

